// rentbook.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: [],
    bookid:null
  },

  openRent: function () {
    var that=this;
    console.log(this.data.info);
    var bookid = this.data.bookid;
    var b1 =null;
    var b2 =null;
    b1=wx.getStorageSync('book1');
    b2=wx.getStorageSync('book2');
    console.log(b1);
    console.log(b2);
    var empty='';
    if (b1 == bookid||b2==bookid) {
      wx.showModal({
        title: '请勿重复借书',
        showCancel: false,
        content: '您已将此书放入借书栏',
        confirmText: '确定',
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      });
      return;
    }
    if (b1 == empty && b2 == empty) {
      wx.setStorageSync('book1', bookid);
      wx.setStorageSync('info1', that.data.info);
      // wx.setStorage({
      //   key: 'book1',
      //   data: bookid,
      // });
      wx.showToast({
        title: '已放入借书栏！',
      });
    }
    else if (b1 != empty && b2 == empty) {

      wx.setStorageSync('book2', bookid);
      wx.setStorageSync('info2', that.data.info);
      // wx.setStorage({
      //   key: 'book2',
      //   data: bookid,
      // });
      wx.showToast({
        title: '已放入借书栏！',
      });
    }
    else if (b1 != empty && b2 != empty){
      wx.showModal({
        title: '借书栏已满',
        showCancel:false,
        content: '每次只能借阅2本，请打开"本次借阅"选择删去借阅书籍',
        confirmText: '确定',
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })
    }

  },
  openCancle:function(){
    wx.navigateBack({
    })
  },
  /**
 * 生命周期函数--监听页面加载
 */
  onLoad: function (options) {
    var that = this;
    var bookid = options.bookid;
    wx.request({
      url: 'https://55300249.qcloud.la/JapariFriends/searchBook?condition1=BookId=\'' + bookid + '\'',
      success: function (res) {
        that.setData({
          info: res.data[0],
          bookid:bookid
        })
      }
    })
  },


})